﻿@using CRM.Admin.Areas.Customer.Controllers
@using CRM.Admin.Contracts.Dto.Customer
@using CRM.Admin.Contracts.Dto.Sys
@using CRM.Admin.Contracts.Model.Customer
@using KingsSharp.Common.Extensions
@using KingsSharp.Core.Data.Entity
@model CRM.Admin.Contracts.Model.Customer.Customer
@{
    ViewBag.Title = "CustomerInfoEdit";
}
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/xlayer/extend/layer.ext.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
    <script src="@Url.Content("~/ScriptPlugin/WdatePicker/js/WdatePicker.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/form2json.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.extended.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/picdata.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.linq.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/webuploader/webuploader.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.Uploader.js")"></script>
    <style type="text/css">
        .uploader {
            text-align: center;
            float: left;
            width: 50px;
            height: 32px;
            line-height: 32px;
            color: blue;
        }

        .uploader-show {
            float: left;
            width: 70%;
            line-height: 32px;
        }

            .uploader-show a {
                margin-right: 5px;
                color: green;
            }

            .uploader-show img {
                width: 100%;
                height: 32px;
            }

                .uploader-show img.mulit {
                    width: 32px;
                    height: 32px;
                    padding-right: 5px;
                    border: 1px solid #fff;
                    margin-left: 3px;
                }

                .uploader-show img.red {
                    border: 1px solid red;
                }

            .uploader-show .imgBox .removeImg {
                margin-top: 9px;
                display: block;
                width: 40px;
                float: left;
                text-align: center
            }

            .uploader-show .imgBox .hongcha {
                position: absolute;
                width: 13px !important;
                height: 13px !important;
                right: -10px;
                top: -5px;
                display: none;
            }

            .uploader-show .imgBox:hover .hongcha {
                display: block;
                cursor: pointer;
            }

            .uploader-show .imgBox {
                position: relative;
                width: 32px;
                float: left;
                margin-left: 10px;
            }
    </style>
}
<form action="" id="customerForm">
    <div class="content-form" id="content-form">
        <table class="content-table">
            <tr>
                <th><span>顾客名称</span></th>
                <td>
                    <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                    <input type="hidden" id="CustomerId" name="CustomerId" value="@Model.Id" data-filter="true" />
                    <input type="text" maxlength="50" data-valid="required" id="Name" name="Name" value="@Model.Name" />
                </td>
                <th><span>顾客简称</span></th>
                <td>
                    <input type="text" maxlength="50" data-valid="required" id="ShortName" name="ShortName" value="@Model.ShortName" />
                </td>
                <th>顾客编码</th>
                <td>
                    <input type="text" maxlength="50" disabled="disabled" id="Code" name="Code" placeholder="自动生成" value="@Model.Code" />
                </td>
                <th>销售系统编码</th>
                <td>
                    <input type="text" maxlength="50" id="SaleSysCode" name="SaleSysCode" value="@Model.SaleSysCode" />
                </td>
            </tr>
            <tr id="datapicke">
                <th><span>注册省</span></th>
                <td>
                    <select data-picke="1" id="ProvinceCode" data-valid="required" name="ProvinceCode"></select>
                    <input type="hidden" id="Province" name="Province" value="@Model.CustomerAddress.Province" />
                </td>
                <th><span>注册市</span></th>
                <td>
                    <select data-picke="2" id="CityCode" data-valid="required" name="CityCode"></select>
                    <input type="hidden" id="City" name="City" value="@Model.CustomerAddress.City" />
                </td>
                <th><span>注册区</span></th>
                <td>
                    <select data-picke="3" id="BoroughCode"  name="BoroughCode"></select>
                    <input type="hidden" id="Borough" name="Borough" value="@Model.CustomerAddress.Borough" />
                </td>
                <th><span>邮政编码</span></th>
                <td>
                    <input type="text" maxlength="50" data-valid="required" id="PostCode" name="PostCode" value="@Model.CustomerAddress.PostCode" />
                </td>
            </tr>
            <tr>
                <th><span>注册地址</span></th>
                <td colspan="7">
                    <input type="text" maxlength="500" data-valid="required" id="AddressDescription" name="AddressDescription" value="@Model.CustomerAddress.Description" />

                    <input type="hidden" id="CustomerAddressId" name="CustomerAddressId" value="@Model.CustomerAddressId" />
                </td>
            <tr id="datapicke1">
                <th>省</th>
                <td>
                    <select data-picke="1" id="ProvinceCode1" name="ProvinceCode1"></select>
                    <input type="hidden" id="Province1" name="Province1" value="@Model.CustomerAddress.Province1" />
                </td>
                <th>市</th>
                <td>
                    <select data-picke="2" id="CityCode1" name="CityCode1"></select>
                    <input type="hidden" id="City1" name="City1" value="@Model.CustomerAddress.City1" />
                </td>
                <th>区</th>
                <td>
                    <select data-picke="3" id="BoroughCode1" name="BoroughCode1"></select>
                    <input type="hidden" id="Borough1" name="Borough1" value="@Model.CustomerAddress.Borough1" />
                </td>
            <tr>
                <th>地址</th>
                <td colspan="7">
                    <input type="text" maxlength="500" id="AddressDescription1" name="AddressDescription1" value="@Model.CustomerAddress.Description1" />
                    <input type="hidden" id="CustomerAddressId" name="CustomerAddressId" value="@Model.CustomerAddressId" />
                </td>
            </tr>

            <tr>
                <th>企业规模/年经营额</th>
                <td>
                    <input type="text" maxlength="20" id="Scale" name="Scale" value="@Model.Scale" />
                </td>
                <th><span>主营业务</span></th>
                <td>
                    <input type="text" maxlength="20" data-valid="required" id="Business" name="Business" value="@Model.Business" />
                </td>
                <th><span>所属行业</span></th>
                <td>
                    <select id="Industry" name="Industry" data-valid="required">
                        <option></option>
                        @{
                            List<DictionaryDto> lbdtos = new List<DictionaryDto>();
                            lbdtos = (List<DictionaryDto>)ViewData[CustomerInfoController.DicCatalogType.KHHY];
                            foreach (var dto in lbdtos)
                            {
                                if (Model.Industry == dto.Name)
                                {
                                    <option value="@dto.Name" selected="selected">@dto.Name</option>
                                }
                                else
                                {
                                    <option value="@dto.Name">@dto.Name</option>
                                }
                            }
                        }
                    </select>
                </td>
                <th>资信情况</th>
                <td>
                    <input type="text" maxlength="20" id="CreditInfo" name="CreditInfo" value="@Model.CreditInfo" />
                </td>
            </tr>
            <tr>
                <th><span>法人代表</span></th>
                <td>
                    <input type="text" maxlength="20" data-valid="required" id="LegalMan" name="LegalMan" value="@Model.LegalMan" />
                </td>
                <th>顾客类别</th>
                <td>
                    <select id="Type" name="Type">
                        <option></option>
                        @{
                            lbdtos = (List<DictionaryDto>)ViewData[CustomerInfoController.DicCatalogType.KHLB];
                            foreach (var dto in lbdtos)
                            {
                                if (Model.Type == dto.Name)
                                {
                                    <option value="@dto.Name" selected="selected">@dto.Name</option>
                                }
                                else
                                {
                                    <option value="@dto.Name">@dto.Name</option>
                                }
                            }
                        }
                    </select>
                </td>
                <th>与我公司合作状态</th>
                <td>
                    <input type="text" name="CooperationState" id="CooperationState" value="@Model.CooperationState" />
                </td>
                <th></th>
                <td></td>
            </tr>
            <tr>
                <th>组织机构代码</th>
                <td>
                    <input type="text" maxlength="20" id="OrganizationCode" name="OrganizationCode" value="@Model.OrganizationCode" />
                </td>
                <th>
                    组织机构代证书
                </th>
                <td>
                    <input type="hidden" id="OrganizationImageUrl" name="OrganizationImageUrl" value="@Model.OrganizationImageUrl" />
                    <div id="picker" class="uploader">
                        上传
                    </div>
                    <div class="uploader-show">
                        @if (Model.OrganizationImageUrl != null)
                        {
                            foreach (var d in Model.OrganizationImageUrl.Split(','))
                            {
                                <div class="imgBox">
                                    <img onclick="showBigImg($(this))" src="@Url.Content("~/"+d)" class="mulit">
                                    <img onclick="removeImg($(this))" src="/Images/hongcha.png" class="hongcha">
                                </div>
                            }
                        }
                    </div>
                </td>
                <th>税务登记号</th>
                <td>
                    <input type="text" maxlength="20" id="TaxRegistrationCode" name="TaxRegistrationCode" value="@Model.TaxRegistrationCode" />
                </td>
                <th>税务登记证证件</th>
                <td>
                    <input type="hidden" id="TaxRegistrationImageUrl" name="TaxRegistrationImageUrl" value="@Model.TaxRegistrationImageUrl" />
                    <div id="picker1" class="uploader">
                        上传
                    </div>
                    <div class="uploader-show">
                        @if (Model.TaxRegistrationImageUrl != null)
                        {
                            foreach (var d in Model.TaxRegistrationImageUrl.Split(','))
                            {
                                <div class="imgBox">
                                    <img onclick="showBigImg($(this))" src="@Url.Content("~/"+d)" class="mulit">
                                    <img onclick="removeImg($(this))" src="/Images/hongcha.png" class="hongcha">
                                </div>
                            }
                        }
                    </div>
                </td>
            </tr>
            <tr>
                <th>营业执照</th>
                <td colspan="3">
                    <input type="hidden" id="LicenseImageUrl" name="LicenseImageUrl" value="@Model.LicenseImageUrl" />

                    <div id="picker2" class="uploader">
                        上传
                    </div>
                    <div class="uploader-show" data-mulit="true">
                        @if (Model.LicenseImageUrl != null)
                        {
                            foreach (var d in Model.LicenseImageUrl.Split(','))
                            {
                                <div class="imgBox">
                                    <img onclick="showBigImg($(this))" src="@Url.Content("~/"+d)" class="mulit">
                                    <img onclick="removeImg($(this))" src="/Images/hongcha.png" class="hongcha">
                                </div>
                            }
                        }
                    </div>
                </td>
                <th>银行资信证明</th>
                <td colspan="3">
                    <input type="hidden" id="BankLicenseImageUrl" name="BankLicenseImageUrl" value="@Model.BankLicenseImageUrl" />
                    <div id="picker3" class="uploader">
                        上传
                    </div>
                    <div class="uploader-show" data-mulit="true">
                        @if (Model.BankLicenseImageUrl != null)
                        {
                            foreach (var d in Model.BankLicenseImageUrl.Split(','))
                            {
                                <div class="imgBox">
                                    <img onclick="showBigImg($(this))" src="@Url.Content("~/"+d)" class="mulit">
                                    <img onclick="removeImg($(this))" src="/Images/hongcha.png" class="hongcha">
                                </div>
                            }
                        }
                    </div>
                </td>
            </tr>
            <tr>
                <th>开户银行</th>
                <td>
                    <input type="text" maxlength="20" id="TicketBank" name="TicketBank" value="@Model.TicketBank" />
                </td>
                <th>开户账号</th>
                <td>
                    <input type="text" maxlength="20" id="TicketBankAccount" name="TicketBankAccount" value="@Model.TicketBankAccount" />
                </td>
                <th>开户信息附件</th>
                <td colspan="3">
                    <input type="hidden" id="TicketAttachment" name="TicketAttachment" value="@Model.TicketAttachment" />
                    <div id="picker4" class="uploader" data-type="file">
                        上传
                    </div>
                    <div class="uploader-show" data-mulit="true">
                        @if (Model.TicketAttachment != null)
                        {
                            foreach (var d in Model.TicketAttachment.Split(','))
                            {
                                <a href="@Url.Content("~/"+d)">(@d.Split('_')[1])</a>
                            }
                        }
                    </div>
                    <input type="hidden" value="@Model.Profiles" name="Profiles" />
                    <input type="hidden" value="@Model.ProfilesAttachment" name="ProfilesAttachment" />
                </td>
            </tr>

            @*<tr>
                    <th>顾客简介</th>
                    <td colspan="7">
                        <textarea rows="4" id="Profiles" name="Profiles">@Model.Profiles</textarea>
                    </td>
                </tr>*@
            @*<tr>
                    <th>顾客简介（附件）</th>
                    <td colspan="7">
                        <input type="hidden" id="ProfilesAttachment" name="ProfilesAttachment" value="@Model.ProfilesAttachment" />
                        <div id="picker5" class="uploader" data-type="file">
                            上传
                        </div>
                        <div class="uploader-show" data-mulit="true">
                            @if (Model.ProfilesAttachment != null)
                            {
                                foreach (var d in Model.ProfilesAttachment.Split(','))
                                {
                                    <a href="@Url.Content("~/"+d)">(@d.Split('_')[1])</a>
                                }
                            }
                        </div>
                    </td>
                </tr>*@
            <tr>
                <th>关联顾客名称</th>
                <td>
                    @{
                        string pName = Model.ParentCustomer != null ? Model.ParentCustomer.Name : "";
                    }
                    <input type="text" readonly="readonly" maxlength="20" value="@pName" id="ParentCustomer" name="ParentCustomer" class="p-icon-right p-icon-customer" />
                    <input type="hidden" id="ParentId" name="ParentId" value="@Model.ParentId" />
                </td>
                <th>顾客信用评价</th>
                <td>
                    <select id="CreditRatings" name="CreditRatings">
                        <option></option>
                        @{
                            lbdtos = (List<DictionaryDto>)ViewData[CustomerInfoController.DicCatalogType.KHXYPJ];
                            foreach (var dto in lbdtos)
                            {
                                if (Model.CreditRatings == dto.Name)
                                {
                                    <option value="@dto.Name" selected="selected">@dto.Name</option>
                                }
                                else
                                {
                                    <option value="@dto.Name">@dto.Name</option>
                                }
                            }
                        }
                    </select>
                </td>
                <th>顾客年度协议完成情况</th>
                <td colspan="3">
                    <input type="text" maxlength="20" id="AgreementFilishProfiles" name="AgreementFilishProfiles" value="@Model.AgreementFilishProfiles" />
                </td>
            </tr>
            <tr>
                <th>潜在顾客需求</th>
                <td colspan="7">
                    <textarea rows="4" id="Demand" name="Demand">@Model.Demand</textarea>
                </td>
            </tr>
            <tr>
                <th>潜在顾客需求（附件）</th>
                <td colspan="7">
                    <input type="hidden" id="DemandFilePath" name="DemandFilePath" value="@Model.DemandFilePath" />
                    <div id="picker6" class="uploader" data-type="file">
                        上传
                    </div>
                    <div class="uploader-show" data-mulit="true">
                        @if (Model.DemandFilePath != null)
                        {
                            foreach (var d in Model.DemandFilePath.Split(','))
                            {
                                <a href="@Url.Content("~/"+d)">(@d.Split('_')[1])</a>
                            }
                        }
                    </div>
                </td>
            </tr>
            <tr>
                <th>备注</th>
                <td colspan="7">
                    <input type="text" maxlength="500" id="Remark" name="Remark" value="@Model.Remark" />
                </td>
            </tr>
        </table>
        <div class="caption ktabs">
            <ul>
                <li class="selected">联系人*</li>
                <li>顾客性质*</li>
                <li>工艺流程*</li>
                <li>产品零件/销售品种*</li>
                <li>采购渠道*</li>
                <li>品种需求*</li>
                <li>品种需求(历年)*</li>
                <li>服务管理*</li>
                <li>顾客归属*</li>
                <li>竞争对手*</li>
                <li>顾客简介*</li>
                <li>顾客协议*</li>
                <li>推广计划*</li>
            </ul>
        </div>
        <div class="ktabs-details" style="height:300px">
            <div id="linkmanGrid">
                <div id="linkpannel">
                    <div class="content-pannel-buttons">
                        <a onclick="LinkManAdd()">
                            <b class="p-icon-add">
                                新增联系人
                            </b>
                        </a><a onclick="LinkManEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="LinkManAddDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>

                </div>
            </div>
            <div id="natureGrid">
                <div id="naturepannel">
                    <div class="content-pannel-buttons">
                        <a onclick="NatureAdd()">
                            <b class="p-icon-add">
                                添加性质
                            </b>
                        </a><a onclick="NatureEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="NatureDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>
            <div id="technologyGrid">
                <div id="technologypannel">
                    <div class="content-pannel-buttons">
                        <a onclick="TechnologyAdd()">
                            <b class="p-icon-add">
                                添加生产工艺
                            </b>
                        </a><a onclick="TechnologyEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="TechnologyDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>

            <div id="productGrid">
                <div id="productpannel">
                    <div class="content-pannel-buttons">
                        <a onclick="ProductAdd()">
                            <b class="p-icon-add">
                                添加产品
                            </b>
                        </a><a onclick="ProductEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="ProductDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>

            <div id="purchaseGrid">
                <div id="purchasepannel">
                    <div class="content-pannel-buttons">
                        <a onclick="PurchaseAdd()">
                            <b class="p-icon-add">
                                添加采购渠道
                            </b>
                        </a>
                        <a onclick="PurchaseEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="PurchaseDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>

            <div id="varietyGrid">
                <div id="varietypannel">
                    <div class="content-pannel-buttons">
                        <a onclick="VarietyAdd()">
                            <b class="p-icon-add">
                                添加品种需求
                            </b>
                        </a>
                        <a onclick="VarietyEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="VarietyDelete()"><b class="p-icon-delete">删除</b></a>
                        <a id="pickerB"><b class="p-icon-excle">导入Excel</b></a>
                        <a id="varietyExport" href="/Customer/GetCustomerData/ExportVariety?customerId=@Model.Id" target="_blank"><b class="p-icon-excle">导出Excel</b></a>
                    </div>
                </div>
            </div>

            <div id="varietyYearGrid">
                <div id="varietyYearpannel">
                    <div class="content-pannel-buttons">
                        <a onclick="VarietyYearAdd()">
                            <b class="p-icon-add">
                                添加品种需求(历年)
                            </b>
                        </a>
                        <a onclick="VarietyYearEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="VarietyYearDelete()"><b class="p-icon-delete">删除</b></a>
                        <a id="pickerA"><b class="p-icon-excle">导入Excel</b></a>
                        <a id="varietyYearExport" href="/Customer/GetCustomerData/ExportVarietyYear?customerId=@Model.Id" target="_blank"><b class="p-icon-excle">导出Excel</b></a>
                    </div>
                </div>
            </div>

            <div id="serveMgGrid">
                <div id="serveMgpannel">
                    <div class="content-pannel-buttons">
                        <a onclick="ServeMgAdd()">
                            <b class="p-icon-add">
                                添加
                            </b>
                        </a>
                        <a onclick="ServeMgEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="ServeMgDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>
            <div id="ascriptionGrid">
                <div id="ascriptionpannel">
                    <div class="content-pannel-buttons">
                        <a onclick="AscriptionAdd()">
                            <b class="p-icon-add">
                                添加
                            </b>
                        </a>
                        <a onclick="AscriptionEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="AscriptionDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>

            <div id="competitorGrid">
                <div id="competitorpannel">
                    <div class="content-pannel-buttons">
                        <a onclick="CompetitorAdd()">
                            <b class="p-icon-add">
                                添加
                            </b>
                        </a>
                        <a onclick="CompetitorEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="CompetitorDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>

            <div id="CustomerProfilesGrid">
                <div id="CustomerProfilespannel">
                    <div class="content-pannel-buttons">
                        <a onclick="CustomerProfilesAdd()">
                            <b class="p-icon-add">
                                添加
                            </b>
                        </a>
                        <a onclick="CustomerProfilesEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="CustomerProfilesDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>
            <div id="CustomerAgreementGrid">
                <div id="CustomerAgreementpannel">
                    <div class="content-pannel-buttons">
                        <a onclick="CustomerAgreementAdd()">
                            <b class="p-icon-add">
                                添加
                            </b>
                        </a>
                        <a onclick="CustomerAgreementEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="CustomerAgreementDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>
            <div id="PromotionPlanGrid">
                <div id="PromotionPlanpannel">
                    <div class="content-pannel-buttons">
                        <a onclick="PromotionPlanAdd()">
                            <b class="p-icon-add">
                                添加
                            </b>
                        </a>
                        <a onclick="PromotionPlanEdit()"><b class="p-icon-edit">编辑</b></a>
                        <a onclick="PromotionPlanDelete()"><b class="p-icon-delete">删除</b></a>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>
@section foot
{
    <script type="text/javascript">
        var linkMansJson = [], naturesJson = [];
        @{
            if (Model.LinkMans != null)
            {
                foreach (var linkMan in Model.LinkMans)
                {
                    LinkManDto dto = linkMan.MapTo<LinkManDto>();
                    <text>linkMansJson.push(@MvcHtmlString.Create(dto.ToJsonString()));</text>
                }
            }

            if (Model.CustomerNatures != null)
            {
                foreach (var nature in Model.CustomerNatures)
                {
                    CustomerNatureDto dto = nature.MapTo<CustomerNatureDto>();
                    <text>naturesJson.push({ "Id": "@nature.Id", "NatureCatalogName": "@nature.Nature.NatureCatalog.Name", "Value": "@nature.Nature.Value" });</text>
                }
            }
        }
        function SaveData(index) {
            if ($("#customerForm").valid()) {

                $("#datapicke").find("select").each(function() {
                    var tx = $(this).find("option:selected").text();
                    $(this).parent().find("input[type='hidden']").val(tx);
                });

                var dto = $("#customerForm").serializeJson();
                dto.LinkMans = $("#linkmanGrid").datagrid('getRows');
                dto.CustomerNatures = $("#natureGrid").datagrid('getRows');
                K.AjaxJson("@Url.Content("~/Customer/CustomerInfo/CustomerUpdate")", dto, function(result) {
                    parent.K.layer.callback(index, result, dto);
                    parent.K.layer.close(index);
                });
            }
        }

        K.PickeInit("datapicke", "@Model.CustomerAddress.ProvinceCode,@Model.CustomerAddress.CityCode,@Model.CustomerAddress.BoroughCode");
        K.PickeInit("datapicke1", "@Model.CustomerAddress.ProvinceCode1,@Model.CustomerAddress.CityCode1,@Model.CustomerAddress.BoroughCode1");


        function LinkManInit() {
            var columns = [
                [
                    { field: "Job", title: "职务", width: 100 },
                    { field: "Phone", title: "手机号码", width: 100 },
                    { field: "Tel", title: "座机号码", width: 100 },
                    { field: "Fax", title: "传真号码", width: 100 },
                    { field: "Email", title: "电子邮箱", width: 100 },
                    { field: "PostCode", title: "邮政编码", width: 100 },
                    { field: "Address", title: "详细地址", width: 100 },
                     { field: "QQnumber", title: "QQ号", width: 100 }
                ]
            ];
            var forzencolumns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "Name", title: "联系人", width: 130 },
                    { field: "Department", title: "所属部门", width: 90 }
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                frozenColumns: forzencolumns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#linkpannel",
                emptyMsg: "暂无联系人",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/GetCustomerData/contacts")"//联系人
            };
            var grid = K.GetGridData("#linkmanGrid", parameter).Grid;
        }

        LinkManInit();

        function LinkManAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加联系人")",
                content: "@Url.Content("~/Customer/CustomerInfo/LinkManAdd")?CustomerId=@Model.Id",
                maxmin: true,
                area: ["80%", "80%"],
                callback: function(linkmanRow) {
                    $("#linkmanGrid").datagrid("load");
                }
            });
        }
        LinkManInit();
        function LinkManEdit() {
            var row = $("#linkmanGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑联系人信息")",
                content: "@Url.Content("~/Customer/LinkMan/LinkManEdit")?CustomerId=" + row.Id,
                maxmin: true,
                initfull: true,
                btn: ["保存", "返回"],
                callback: function (result) {
                    $("#linkmanGrid").datagrid("load");
                }
            });
        }
        function NatureInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "NatureCatalogName", title: "性质名称", width: 100 },
                    { field: "Value", title: "性质内容", width: 500 }
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#naturepannel",
                emptyMsg: "顾客还没有任何性质",
                pagination: true,
                queryParams: { Id: $("#Id").val() },
                url: "@Url.Content("~/Customer/GetCustomerData/customerNature")"//顾客性质
            };
            var grid = K.GetGridData("#natureGrid", parameter).Grid;
        }

        NatureInit();
        function NatureAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "选择顾客性质")",
                content: "@Url.Content("~/Customer/Nature/NatureChecked")",
                maxmin: true,
                area: ["80%", "80%"],
                callback: function(checkedRows) {
                    for (var i = 0; i < checkedRows.length; i++) {
                        var row = checkedRows[i];

                        var rows = $("#natureGrid").datagrid("getRows");
                        var nothas = true;
                        for (var x = 0; x < rows.length; x++) {
                            if (rows[x].NatureId == row.NatureId) {
                                nothas = false;
                            }
                        }
                        if (nothas) {
                            K.AjaxJson("@Url.Content("~/Customer/CustomerInfo/CustomerNatureInsert")?CustomerId=@Model.Id", row, function(result) {
                                if (K.ShowOrAlert(result)) {
                                    $("#natureGrid").datagrid("load");
                                }
                            });
                        }
                    }
                }
            });
        }
        NatureInit();
        function NatureEdit() {
            var row = $("#natureGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑顾客性质")",
                content: "@Url.Content("~/Customer/Nature/NatureEdit")?NatureId=" + row.NatureId,
            maxmin: true,
            initfull: true,
            btn: ["保存", "返回"],
            callback: function (result) {
                $("#natureGrid").datagrid("load");
            }
        });
        }
        function TechnologyInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "Profiles", title: "生产工艺简介", width: 150 },
                    { field: "ProcessGetDate", title: "流程收集日期", width: 85 },
                    { field: "ProcessUser", title: "流程收集人", width: 85 },
                    { field: "EquipmentProfiles", title: "设备介绍", width: 85 },
                    { field: "EquipmentGetDate", title: "设备收集日期", width: 85 },
                    { field: "EquipmentGetUser", title: "设备收集人", width: 85 },
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#technologypannel",
                emptyMsg: "无工艺流程",
                pagination: true,
                queryParams: { Id: $("#Id").val() },
                url: "@Url.Content("~/Customer/GetCustomerData/artsProcess")"//工艺流程
            };
            var grid = K.GetGridData("#technologyGrid", parameter).Grid;
        }

        TechnologyInit();

        function TechnologyAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加生产工艺")",
                content: "@Url.Content("~/Customer/CustomerInfo/TechnologyAdd")?CustomerId=@Model.Id",
                maxmin: true,
                area: ["80%", "80%"],
                callback: function(linkmanRow) {
                    $("#technologyGrid").datagrid("load");
                }
            });
        }
        TechnologyInit();
        function TechnologyEdit() {
            var row = $("#technologyGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑生产工艺")",
                content: "@Url.Content("~/Customer/CustomerInfo/TechnologyEdit")?CustomerId=@Model.Id&Id="+row.Id,
            maxmin: true,
            area: ["80%", "80%"],
            callback: function(linkmanRow) {
                $("#technologyGrid").datagrid("load");
            }
        });
        }

        function PurchaseInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "BreedName", title: "采购品种", width: 150 },
                    {field:"MaterialMade",title:"原料材质",width:150},
                    { field: "Year", title: "采购时间", width: 85 },
                    { field: "SupplierName", title: "钢材/供应商名称", width: 105 },
                    { field: "Weight", title: "采购重量", width: 85 }
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#purchasepannel",
                emptyMsg: "无采购渠道",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/GetCustomerData/purchaseChannel")"//采购渠道
            };
            var grid = K.GetGridData("#purchaseGrid", parameter).Grid;
        }

        PurchaseInit();

        function PurchaseAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加采购渠道")",
                content: "@Url.Content("~/Customer/Purchase/PurchaseAdd")?CustomerId=@Model.Id",
                maxmin: true,
                area: ["95%", "95%"],
                callback: function (result, purchaseRow) {
                    if (K.ShowOrAlert(result)) {
                        $("#purchaseGrid").datagrid("load");
                    }
                }
            });
        }
        function PurchaseEdit() {
            var row = $("#purchaseGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑采购渠道")",
                content: "@Url.Content("~/Customer/Purchase/PurchaseEdit")?CustomerId=@Model.Id&PurchaseId=" + row.Id,//编辑采购渠道
                maxmin: true,
                area: ["95%", "95%"],
                callback: function (result, purchaseRow) {
                    if (K.ShowOrAlert(result)) {
                        $("#purchaseGrid").datagrid("load");
                    }
                }
            });
        }

        function ProductInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "Name", title: "产品/零件名称", width: 150 },
                    { field: "SaleWeight", title: "年产量/销售量", width: 85 },
                    { field: "NeedSteelWeight", title: "需钢材量", width: 85 },
                    { field: "UseSteelType", title: "使用钢材品种", width: 85 },
                    { field: "Consumption", title: "使用钢材品种单耗", width: 95 },
                    {
                        field: "test",
                        title: "零件明细",
                        width: 85,
                        formatter: function (val, row, index) {
                            return "<a style=\"color:blue\" onclick=\"showComponentList('" + row.Id + "')\">查看零件明细</a>";
                        }
                    },
                    {
                        field: "test1",
                        title: "添加零件",
                        width: 85,
                        formatter: function (val, row, index) {
                            //return "<a style=\"color:blue\" onclick=\"ComponentAdd('" + row.Id + "')\">添加</a>";

                            return "<a style=\"color:blue\" onclick=\"ComponentAdd('" + row.Id + "')\">添加</a>";
                        }
                    }
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#productpannel",
                emptyMsg: "无产品",
                pagination: true,
                queryParams: { Id: $("#Id").val() },
                 url: "@Url.Content("~/Customer/GetCustomerData/product")"//产品零件
            };
            var grid = K.GetGridData("#productGrid", parameter).Grid;
        }

        ProductInit();

        function ProductAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加产品/品种")",
                content: "@Url.Content("~/Customer/Product/ProductAdd")?CustomerId=@Model.Id",
                maxmin: true,
                area: ["80%", "80%"],
                callback: function(productRow) {
                    $("#productGrid").datagrid("load");
                }
            });
        }

        ProductInit();

        function ProductEdit() {
            var row = $("#productGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑产品/品种")",
            content: "@Url.Content("~/Customer/Product/ProductEdit")?CustomerId=@Model.Id&Id="+row.Id,
            maxmin: true,
            area: ["80%", "80%"],
            callback: function(productRow) {
                $("#productGrid").datagrid("load");
            }
        });
        }
        function ComponentAdd(productId) {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加零件")",
                content: "@Url.Content("~/Customer/Product/ComponentAdd")?ProductId=" + productId,
                maxmin: true,
                area: ["80%", "80%"],
                callback: function(result) {
                    K.ShowOrAlert(result);
                }
            });
        }
        function showComponentList(productId) {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "查看零件明细")",
                content: "@Url.Content("~/Customer/Product/ComponentList")?ProductId=" + productId,
                maxmin: true,
                btn:null
            });
        }

        //竞争对手相关
        function CompetitorInit() {
            var columns = [
                [
                    { field: "ProQualityLevel", title: "产品质量水平", width: 130 },
                    { field: "ContractDelivery", title: "合同交货情况", width: 130 },
                    { field: "MarketStrategy", title: "主要营销策略", width: 130 },
                    { field: "SupplyRelation", title: "顾客供货关系", width: 130 },
                    { field: "SupplyDesc", title: "供货简介", width: 130 },
                    { field: "Problem", title: "存在问题", width: 130 },
                    { field: "ProductShare", title: "产品占有率", width: 100 }
                ]
            ];
            var forzencolumns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "Name", title: "竞争对手名称", width: 200 }
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                frozenColumns: forzencolumns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#competitorpannel",
                emptyMsg: "暂无竞争对手信息",
                pagination: true,
                queryParams: { Id: $("#Id").val() },
                url: "@Url.Content("~/Customer/GetCustomerData/competitor")"//品种需求
            };
            var grid = K.GetGridData("#competitorGrid", parameter).Grid;
        }

        CompetitorInit();

        function CompetitorAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加竞争对手信息")",
                content: "@Url.Content("~/Customer/Competitor/CompetitorAdd")?CustomerId=@Model.Id",
                maxmin: true,
                area: ["80%", "80%"],
                btn: ["保存", "返回"],
                callback: function(result) {
                    if (K.ShowOrAlert(result)) {
                        $("#competitorGrid").datagrid("load");
                    }
                }
            });
        }

        function CompetitorEdit() {
            var row = $("#competitorGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑竞争对手信息")",
                content: "@Url.Content("~/Customer/Competitor/CompetitorEdit")?CompetitorId=" + row.Id,
                maxmin: true,
                initfull: true,
                btn: ["保存", "返回"],
                callback: function (result, varietyRow) {
                    if (K.ShowOrAlert(result)) {
                        $("#competitorGrid").datagrid("load");
                    }
                }
            });
        }
        //顾客简介
        function CustomerProfilesInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "YearProfiles", title: "简介年份", width: 85 },
                    { field: "Profiles", title: "顾客简介", width: 800 },

                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#CustomerProfilespannel",
                emptyMsg: "无顾客简介",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/GetCustomerData/CustomerProfiles")"
            };
            var grid = K.GetGridData("#CustomerProfilesGrid", parameter).Grid;
        }

        CustomerProfilesInit();

        function CustomerProfilesAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加顾客简介")",
                content: "@Url.Content("~/Customer/CustomerProfiles/CustomerProfilesAdd")?CustomerId=@Model.Id",
            maxmin: true,
            area: ["80%", "80%"],
            btn: ["保存", "返回"],
            callback: function (result, varietyRow) {
                if (K.ShowOrAlert(result)) {
                    $("#CustomerProfilesGrid").datagrid("load");
                }
            }
        });
        }

        function CustomerProfilesEdit() {
            var row = $("#CustomerProfilesGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑顾客简介")",
                content: "@Url.Content("~/Customer/CustomerProfiles/CustomerProfilesEdit")?Id=" + row.Id,
            maxmin: true,
            initfull: true,
            btn: ["保存", "返回"],
            callback: function (result, varietyRow) {
                if (K.ShowOrAlert(result)) {
                    $("#CustomerProfilesGrid").datagrid("load");
                }
            }
        });
        }
        //品种需求
        function VarietyInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "ParticularYear", title: "需求年份", width: 85 },
                    {
                        field: "Month", title: "需求月份", width: 85, formatter: function (val, row, index) {
                            if (val == 13) {
                                return "汇总年需求";
                            } else {
                                return val;
                            }
                    }},
                    { field: "DemandSourcesName", title: "产品/零件名称", width: 150 },
                    { field: "MaterialMade", title: "原料材质", width: 85 },
                    { field: "MaterialSpecs",title:"原料规格",width:85 },
                    { field: "MaterialWeight", title: "原料单件重量(kg)", width: 90 },
                    { field: "MaterialWidth", title: "原料单件宽度", width: 85 },
                    { field: "MaterialThickness", title: "原料单件厚度", width: 85 },
                    { field: "MaterialHeight", title: "原料单件高度", width: 85 },
                    { field: "NowNeedWeight", title: "当月需求量(吨)", width: 85 },

                    { field: "BreedName", title: "对应攀钢品种", width: 85 },
                    { field: "PGFCoverWeight", title: "攀钢钒可覆盖量(吨)", width: 100},
                    { field: "PGFAlreadySupplyWeight", title: "攀钢钒已供应量(吨)", width: 100 },
                    { field: "XGFCoverWeight", title: "西钢钒可覆盖量(吨)", width: 100 },
                    { field: "XGFAlreadySupplyWeight", title: "西钢钒已供应量(吨)", width: 100 },

                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#varietypannel",
                emptyMsg: "无品种需求",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/GetCustomerData/varietyDemand")"//品种需求
            };
            var grid = K.GetGridData("#varietyGrid", parameter).Grid;

        }

        VarietyInit();

        function VarietyAdd() {
            var row = $("#varietyGrid").treegrid("getSelected");
            var id = null;
            if(row!=null){
                id = row.Id;
            }
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加品种需求")",
                content: "@Url.Content("~/Customer/Variety/VarietyAdd")?CustomerId=@Model.Id&GuidId=" + id,
                maxmin: true,
                area: ["95%", "95%"],
                callback: function (result, varietyRow) {
                    if (K.ShowOrAlert(result)) {
                        $("#varietyGrid").datagrid("load");
                    }
                }
            });
        }
        function VarietyEdit() {
            var row = $("#varietyGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑品种需求")",
                content: "@Url.Content("~/Customer/Variety/VarietyEdit")?CustomerId=@Model.Id&Id="+row.Id,
            maxmin: true,
            area: ["95%", "95%"],
            callback: function (result, varietyRow) {
                if (K.ShowOrAlert(result)) {
                    $("#varietyGrid").datagrid("load");
                }
            }
        });
        }
        function VarietyYearInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "ParticularYear", title: "需求年份", width: 85 },
                    { field: "DemandSourcesName", title: "产品/零件名称", width: 150 },
                    { field: "MaterialMade", title: "原料材质", width: 85 },
                    { field: "MaterialSpecs",title:"原料规格",width:85 },
                    { field: "MaterialWeight", title: "原料单件重量(kg)", width: 100 },
                    { field: "MaterialWidth", title: "原料单件宽度", width: 85 },
                    { field: "MaterialThickness", title: "原料单件厚度", width: 85 },
                    { field: "MaterialHeight", title: "原料单件高度", width: 85 },
                    { field: "NowNeedWeight", title: "当年需求量(吨)", width: 95 },
                    { field: "YearNeedProfiles", title: "当年预计需求(吨)", width: 100 },
                    { field: "NextYearNeedProfiles", title: "次年预计需求量(吨)", width: 100 },
                    { field: "BreedName", title: "对应攀钢品种", width: 85 },
                    { field: "PGAlreadySupplyWeight", title: "攀钢已供应量(吨)", width: 100 },
                    { field: "PGCoverWeight", title: "攀钢可覆盖量(吨)", width: 100 },
                    { field: "PGFCoverWeight", title: "攀钢钒可覆盖量(吨)", width: 100 },
                    { field: "PGFAlreadySupplyWeight", title: "攀钢钒已供应量(吨)", width: 100 },
                    //{ field: "XGFCoverWeight", title: "西钢钒可覆盖量", width: 85 },
                    //{ field: "XGFAlreadySupplyWeight", title: "西钢钒已供应量", width: 85 },

                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#varietyYearpannel",
                emptyMsg: "无品种需求",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/GetCustomerData/varietyYearDemand")"//品种需求
        };
        var grid = K.GetGridData("#varietyYearGrid", parameter).Grid;
        }

        VarietyYearInit();
        function VarietyYearAdd() {

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加品种需求(历年)")",
                content: "@Url.Content("~/Customer/VarietyYear/VarietyYearAdd")?CustomerId=@Model.Id",
            maxmin: true,
            area: ["95%", "95%"],
            callback: function (result, varietyRow) {
                if (K.ShowOrAlert(result)) {
                    $("#varietyYearGrid").datagrid("load");
                }
            }
        });
        }
        function VarietyYearEdit() {
            var row = $("#varietyYearGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑品种需求(历年)")",
                content: "@Url.Content("~/Customer/VarietyYear/VarietyYearEdit")?CustomerId=@Model.Id&Id="+row.Id,
            maxmin: true,
            area: ["95%", "95%"],
            callback: function (result, varietyRow) {
                if (K.ShowOrAlert(result)) {
                    $("#varietyYearGrid").datagrid("load");
                }
            }
        });
        }
        //服务管理相关
        function ServeMgInit() {
            var columns = [
                [
                    { field: "Type", title: "服务分类", width: 80 },
                    { field: "StartDate", title: "开始日期", width: 100 },
                    { field: "EndDate", title: "结束日期", width: 100 },
                    { field: "CustomPerson", title: "顾客方人员信息", width: 130 },
                    { field: "PgPerson", title: "攀钢服务人员信息", width: 130 },
                    { field: "Report", title: "服务报告", width: 130 }
                ]
            ];
            var forzencolumns = [
                [
                    { field: "ck", checkbox: true }
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                frozenColumns: forzencolumns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#serveMgpannel",
                emptyMsg: "暂无服务管理信息",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/GetCustomerData/serviceManage")"//服务管理
            };
            var grid = K.GetGridData("#serveMgGrid", parameter).Grid;
        }

        ServeMgInit();

        function ServeMgAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加服务管理信息")",
                content: "@Url.Content("~/Customer/ServeMg/ServeMgAdd")?CustomerId=@Model.Id",
            maxmin: true,
            area: ["80%", "80%"],
            btn: ["保存", "返回"],
            callback: function(result) {
                if (K.ShowOrAlert(result)) {
                    $("#serveMgGrid").datagrid("load");
                }
            }
        });
        }

        function ServeMgEdit() {
            var row = $("#serveMgGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑服务管理信息")",
                content: "@Url.Content("~/Customer/ServeMg/ServeMgEdit")?ServeMgId=" + row.Id,
            maxmin: true,
            initfull: true,
            btn: ["保存", "返回"],
            callback: function(result) {
                $("#serveMgGrid").datagrid("load");
            }
        });
        }
        //顾客协议
        function CustomerAgreementInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "ProdName", title: "品种名称", width: 85 },
                    { field: "Year", title: "年份", width: 50 },
                    { field: "moth", title: "月份", width: 50 },
                    { field: "ProtocolQuantity", title: "协议量", width: 50 },
                    { field: "CompletionQuantity", title: "完成量", width: 50 },

                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#CustomerAgreementpannel",
                emptyMsg: "无顾客协议",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/CustomerAgreement/GetCustomerAgreementData")"
        };
            var grid = K.GetGridData("#CustomerAgreementGrid", parameter).Grid;
        }
        CustomerAgreementInit();

        //推广计划
        function PromotionPlanInit() {
            var columns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "PromotionTime", title: "时间", width: 85 },
                    { field: "Address", title: "地点", width: 250 },
                    { field: "Content", title: "内容", width: 500 },
                    { field: "Result", title: "结果", width: 500 }
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#PromotionPlanpannel",
                emptyMsg: "无推广计划",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/GetCustomerData/PromotionPlans")"
        };
            var grid = K.GetGridData("#PromotionPlanGrid", parameter).Grid;
        }
        PromotionPlanInit();

        //添加推广计划
        function PromotionPlanAdd() {
             K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加推广计划")",
                content: "@Url.Content("~/Customer/PromotionPlan/PromotionPlanAdd")?CustomerId=@Model.Id",
            maxmin: true,
            area: ["80%", "80%"],
            btn: ["保存", "返回"],
            callback: function(result) {
                $("#PromotionPlanGrid").datagrid("load");
            }
        });
        }
        //编辑推广计划
        function PromotionPlanEdit() {
            var row = $("#PromotionPlanGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的推广计划");
                return false;
            }
             K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑推广计划")",
                 content: "@Url.Content("~/Customer/PromotionPlan/PromotionPlanEdit")?id=" + row.Id,
            maxmin: true,
            area: ["80%", "80%"],
            btn: ["保存", "返回"],
            callback: function(result) {
                $("#PromotionPlanGrid").datagrid("load");
            }
        });
        }
         //推广计划删除
        function PromotionPlanDelete() {
            var row = $("#PromotionPlanGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的推广计划");
                return false;
            }
            K.Confirm("确认删除该推广计划？", function () {
                K.AjaxJson("@Url.Content("~/Customer/PromotionPlan/PromotionPlanDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#PromotionPlanGrid").datagrid("load");
                    }
                }, "推广计划删除中");
            });
        }
        //添加顾客协议
        function CustomerAgreementAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加顾客协议信息")",
                content: "@Url.Content("~/Customer/CustomerAgreement/Insert")?CustomerId=@Model.Id",
            maxmin: true,
            area: ["80%", "80%"],
            btn: ["保存", "返回"],
            callback: function(result) {
                    $("#CustomerAgreementGrid").datagrid("load");
            }
        });
        }

        //编辑顾客协议
        function CustomerAgreementEdit() {
           var row = $("#CustomerAgreementGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑顾客协议信息")",
                content: "@Url.Content("~/Customer/CustomerAgreement/Edit")?Id=" + row.Id,
            maxmin: true,
            initfull: true,
            btn: ["保存", "返回"],
            callback: function(result) {
                $("#CustomerAgreementGrid").datagrid("load");
            }
        });
        }
        //顾客归属相关
        function AscriptionInit() {
            var columns = [
                [
                    { field: "DeputyName", title: "顾客代表", width: 100 }
                ]
            ];
            var forzencolumns = [
                [
                    { field: "ck", checkbox: true },
                    { field: "Name", title: "所属机构名称", width: 200 }
                ]
            ];
            var parameter = {
                title: null,
                columns: columns,
                frozenColumns: forzencolumns,
                singleSelect: true,
                pageNumber: 1,
                toolbar: "#ascriptionpannel",
                emptyMsg: "暂无顾客归属信息",
                pagination: true,
                queryParams: {Id:$("#Id").val()},
                url: "@Url.Content("~/Customer/GetCustomerData/customerAttach")"//顾客归属
            };
            var grid = K.GetGridData("#ascriptionGrid", parameter).Grid;
        }

        AscriptionInit();

        function AscriptionAdd() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "添加顾客归属信息")",
                content: "@Url.Content("~/Customer/Ascription/AscriptionAdd")?CustomerId=@Model.Id",
            maxmin: true,
            area: ["80%", "80%"],
            btn: ["保存", "返回"],
            callback: function(result) {
                if (K.ShowOrAlert(result)) {
                    $("#ascriptionGrid").datagrid("load");
                }
            }
        });
        }

        function AscriptionEdit() {
            var row = $("#ascriptionGrid").treegrid("getSelected");
            if (row == null) {
                K.Alert("请选择需要编辑的行");
                return false;
            }

            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit, "编辑顾客归属信息")",
                content: "@Url.Content("~/Customer/Ascription/AscriptionEdit")?AscriptionId=" + row.Id,
            maxmin: true,
            initfull: true,
            btn: ["保存", "返回"],
            callback: function(result) {
                $("#ascriptionGrid").datagrid("load");
            }
        });
        }

    </script>

    <script type="text/javascript">
        var uploaders = [];
        $(".uploader").each(function() {
            var that = $(this);
            var fileType = $(this).attr("data-type");
            var imgshow = that.parent().find(".uploader-show");
            var urlhidden = that.parent().find("input[type='hidden']");
            var pickid = "#" + that.prop("id");
            var ismulit = false;
            var fileInputName = "file";
            if (urlhidden) {
                fileInputName = urlhidden.prop("name");
            }
            if (imgshow.attr("data-mulit")) {
                ismulit = true;
            }

            var parameter = {
                swf: '@Url.Content("~/ScriptPlugin/webuploader/Uploader.swf")',
                server: '@Url.Content("~/Customer/CustomerInfo/UploaderProcess")',
                pick: {
                    id: pickid,
                    multiple: ismulit
                },
                resize: false,
                auto: true,
                fileVal: fileInputName
            };
            var eventer = {
                fileQueued: function(file) {
                    if (fileType && fileType === "file") {
                        if (ismulit) {
                            imgshow.append("（<a>" + file.name + "</a>）");
                        } else {
                            imgshow.html("（<a>" + file.name + "</a>）");
                        }
                    } else {
                        uploader.makeThumb(file, function(error, ret) {
                            if (error) {
                                imgshow.html("预览错误");
                            } else {
                                if (ismulit) {
                                    imgshow.append("<div class=\"imgBox\"><img onclick=\"\" src=\"" + ret + "\" class=\"mulit\"  /><img onclick=\"removeImg($(this))\"  src=\"@Url.Content("~/Images/hongcha.png")\" class=\"hongcha\" /></div>");
                                } else {
                                    imgshow.append("<div class=\"imgBox\"><img onclick=\"\" src=\"" + ret + "\"  /><img onclick=\"removeImg($(this))\"  src=\"@Url.Content("~/Images/hongcha.png")\" class=\"hongcha\" /></div>");
                                }
                            }
                        });
                    }
                },
                uploadSuccess: function(file, response) {
                    if (response.Filish) {
                        if (ismulit) {
                            var oldval = urlhidden.val();
                            if (oldval != "") {
                                oldval += ",";
                            }
                            urlhidden.val(oldval + response.Path);
                        } else {
                            urlhidden.val(response.Path);
                        }
                    }
                },
                uploadError: function() {
                    K.Alert("上传出错");
                }
            };
            if (fileType && fileType === "file") {
                var uploader = new K.Uploader().createFile(parameter, eventer);
                uploaders.push(uploader);
            } else {
                var uploader = new K.Uploader().createImage(parameter, eventer);
                uploaders.push(uploader);
            }
        });
        //查看大图
        function showBigImg(obj) {
                var json = {
                    "data": [
                        {
                            "src": obj.attr("src"), //原图地址
                        }
                    ]
                };
                layer.photos({
                    photos: json
                });
        }
        //删除图片
        function removeImg(obj) {
            var imgUrlStr = obj.closest("td").find("input[type=hidden]");
            var imgUrlArr = imgUrlStr.val().split(",");
            imgUrlArr.splice(obj.parent().index(), 1);
            obj.parent().remove();
            K.Alert("删除成功");
            $("#" + imgUrlStr.attr("id")).val(imgUrlArr.toString());
        }
        //联系人删除
        function LinkManAddDelete() {
            var row = $("#linkmanGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的联系人");
                return false;
            }
            K.Confirm("确认删除联系人 \"" + row.Name + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/CustomerInfo/LinkManAddDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#linkmanGrid").datagrid("load");
                    }
                }, "联系人 \"" + row.Name + "\"删除中...");
            });
        }
        //顾客协议删除
        function CustomerAgreementDelete() {
            var row = $("#CustomerAgreementGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的顾客协议");
                return false;
            }
            K.Confirm("确认删除联系人 \"" + row.Name + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/CustomerAgreement/CustomerAgreementDelete")", { Id: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#CustomerAgreementGrid").datagrid("load");
                    }
                }, "顾客协议删除中");
            });
        }
        //顾客性质删除
        function NatureDelete() {
            var row = $("#natureGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的顾客性质");
                return false;
            }
            K.Confirm("确认删除顾客性质 \"" + row.NatureCatalogName + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/CustomerInfo/CustomerNatureDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#natureGrid").datagrid("load");
                    }
                }, "顾客性质 \"" + row.Name + "\"删除中...");
            });
        }
        //工艺流程删除
        function TechnologyDelete() {
            var row = $("#technologyGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的工艺流程");
                return false;
            }
            K.Confirm("确认删除工艺流程 \"" + row.Profiles + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/CustomerInfo/TechnologyDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#technologyGrid").datagrid("load");
                    }
                }, "工艺流程 \"" + row.Name + "\"删除中...");
            });
        }
        //产品零件删除
        function ProductDelete() {
            var row = $("#productGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的产品零件/销售品种");
                return false;
            }
            K.Confirm("确认删除产品零件/销售品种 \"" + row.Name + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/Product/ProductDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#productGrid").datagrid("load");
                    }
                }, "产品零件/销售品种 \"" + row.Name + "\"删除中...");
            });
        }
        //采购渠道删除
        function PurchaseDelete() {
            var row = $("#purchaseGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的采购渠道");
                return false;
            }
            K.Confirm("确认删除采购渠道 \"" + row.BreedName + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/Purchase/PurchaseDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#purchaseGrid").datagrid("load");
                    }
                }, "采购渠道 \"" + row.Name + "\"删除中...");
            });
        }
        //品种需求删除
        function VarietyDelete() {
            var row = $("#varietyGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的品种需求");
                return false;
            }
            K.Confirm("确认删除品种需求 \"" + row.DemandSourcesName + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/Variety/VarietyDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#varietyGrid").datagrid("load");
                    }
                }, "品种需求 \"" + row.Name + "\"删除中...");
            });
        }

        //品种需求历年删除
        function VarietyYearDelete() {
            var row = $("#varietyYearGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的品种需求");
                return false;
            }
            K.Confirm("确认删除品种需求 \"" + row.DemandSourcesName + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/VarietyYear/VarietyYearDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#varietyYearGrid").datagrid("load");
                    }
                }, "品种需求 \"" + row.Name + "\"删除中...");
            });
        }

        //服务管理删除
        function ServeMgDelete(){
            var row = $("#serveMgGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的服务管理");
                return false;
            }
            K.Confirm("确认删除服务管理 \"" + row.Type + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/ServeMg/ServeMgDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#serveMgGrid").datagrid("load");
                    }
                }, "服务管理 \"" + row.Name + "\"删除中...");
            });
        }
        //顾客归属删除
        function AscriptionDelete(){
            var row = $("#ascriptionGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的顾客归属");
                return false;
            }
            K.Confirm("确认删除顾客归属 \"" + row.Name + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/Ascription/AscriptionDelete")", { UserId: row.Id, }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#ascriptionGrid").datagrid("load");
                    }
                }, "顾客归属 \"" + row.Name + "\"删除中...");
            });
        }
        //竞争对手删除
        function CompetitorDelete(){
            var row = $("#competitorGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的竞争对手");
                return false;
            }
            K.Confirm("确认删除竞争对手 \"" + row.Name + "\" ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/Competitor/CompetitorDelete")", { UserId: row.Id, CompetitorName:row.Name }, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#competitorGrid").datagrid("load");
                    }
                }, "竞争对手 \"" + row.Name + "\"删除中...");
            });
        }
        //顾客简介
        function CustomerProfilesDelete(){
            var row = $("#CustomerProfilesGrid").datagrid("getSelected");
            if (row == null) {
                K.Alert("请选择需删除的顾客简介");
                return false;
            }
            K.Confirm("确认删除 \"" + row.YearProfiles + "\"年顾客简介 ？", function () {
                K.AjaxJson("@Url.Content("~/Customer/CustomerProfiles/CustomerProfilesDelte")", { Id: row.Id}, function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#CustomerProfilesGrid").datagrid("load");
                    }
                }, row.YearProfiles + "\"年顾客简介删除中...");
            });
        }
        //导入功能品种需求
        var uploaderB = new K.Uploader().createExcle({
            swf: '@Url.Content("~/ScriptPlugin/webuploader/Uploader.swf")',
            server: '@Url.Content("~/Customer/Variety/VarietyExcelInsert")?CustomerId=@Model.Id',
            pick: '#pickerB',
            resize: false,
            auto: true
        }, {
            uploadSuccess: function (file, response) {

                if (response.Filish) {

                    K.Alert(response.Message);
                }
                $("#varietyGrid").datagrid("load");
            },
            uploadError: function () {
                K.Alert("上传出错");
            }
        });
        //导入功能品种需求历年
        var uploaderB = new K.Uploader().createExcle({
            swf: '@Url.Content("~/ScriptPlugin/webuploader/Uploader.swf")',
            server: '@Url.Content("~/Customer/VarietyYear/VarietyYearExcelInsert")?CustomerId=@Model.Id',
            pick: '#pickerA',
            resize: false,
            auto: true
        }, {
            uploadSuccess: function (file, response) {

                if (response.Filish) {

                    K.Alert(response.Message);
                }
                $("#varietyYearGrid").datagrid("load");
            },
            uploadError: function () {
                K.Alert("上传出错");
            }
        });
    </script>
}